Release 10.1A: OpenEdge Application Server:
Developing AppServer Applications
Handling the response from an asynchronous request
When an asynchronous request completes execution, it sends a response to the AppServer client, which places it on the response queue for the appropriate server handle. To signify that the response is ready to be processed, the
PROCEDURE-COMPLETEevent is placed on the event queue where it can be processed in the context of blocking I/O statements, such asWAIT-FORor thePROCESS EVENTSstatement.PROCEDURE-COMPLETE events
The
PROCEDURE-COMPLETEevent is an event on the asynchronous request handle. It indicates that the asynchronous request associated with the handle has completed execution, and that the corresponding event procedure can be executed. OpenEdge executes the event procedure in the context of a blocking I/O statement much like it executes the trigger for a user-interface event.Note that you do not have to specify the
PROCEDURE-COMPLETEevent explicitly in your client code. OpenEdge processes the event like any other Progress 4GL event. You also do not have to define a trigger for the event (for example, using anONstatement) because you specify an event procedure in theRUN...ASYNCHRONOUSstatement that defines the “trigger code” for the event.To process a
PROCEDURE-COMPLETEevent for a particular asynchronous request handle, OpenEdge:
- Decrements the
ASYNC-REQUEST-COUNTattribute on the following handles:- Sets the
COMPLETEattribute for the asynchronous request handle toTRUE.- Sets the
STOP,QUIT, orERRORattribute for the asynchronous request handle appropriately as indicated by the response message from the AppServer, and stores any error information returned from the AppServer for the request in theERROR-STATUSsystem handle.- Sets the return value for the
RETURN-VALUEfunction, if a return value was returned by the AppServer.- Attempts to execute the event procedure specified by the
EVENT-PROCEDUREand theEVENT-PROCEDURE-CONTEXTattributes for the asynchronous request handle, ifEVENT-PROCEDUREis not the empty string (""), and:
- Sets each
INPUTparameter for the event procedure to the Unknown value (?) or, if the parameter is aTEMP-TABLEparameter, the temp-table remains unchanged, if the response message indicates that the remote request finished with aSTOP,ERROR, orQUITcondition.- Sets the
INPUTparameter values for the event procedure to theOUTPUTandINPUT-OUTPUTparameter values returned by the remote procedure, if the response message indicates that the remote request completed successfully.- Displays an error message, if a specified event procedure fails to execute for any reason.
Event procedures
To handle the response from an asynchronous request, you must define an event procedure. In this context, an event procedure is an internal procedure that executes in response to a
PROCEDURE-COMPLETEevent. To define an event procedure you must:Typical places where you might define the specified internal procedure include:
- The same procedure context as the
RUN...ASYNCHRONOUSstatement that specifies the event procedure.- An external procedure context that you specify using the
EVENT-PROCEDUREoption on theRUN...ASYNCHRONOUSstatement using its procedure handle. In this case, the external procedure context must be active in the client session before you execute theRUN...ASYNCHRONOUSstatement.You must define the specified internal procedure with
INPUTparameters that correspond in type and order to theOUTPUTandINPUT-OUTPUTparameters that you specify on theRUN...ASYNCHRONOUSstatement.To receive results from the asynchronous request in an event procedure, you can access:
- The asynchronous request handle for the request using the
SELFsystem handle.- The attributes and methods of the
ERROR-STATUSsystem handle to obtain error information from the request.- Values passed as output parameters from the remote procedure to corresponding input parameters in the event procedure.
- The
RETURN-VALUEfunction to get the return value from the request.Obtaining error information
With an asynchronous remote procedure request, the
RUN...ASYNCHRONOUSstatement returns once the client request has been validated. Any errors that occur while processing theRUN...ASYNCHRONOUSstatement are returned as aSTOPorERRORcondition in the context of theRUN...ASYNCHRONOUSstatement. Information on errors that occur once the asynchronous request has been submitted can be obtained by using theERROR-STATUSsystem handle within the event procedure for the asynchronous request.If the asynchronous request completes with a condition, you can use attributes on the asynchronous request handle to determine the condition that the request completed with, as follows:
Note that any asynchronous request that raises the
STOPcondition (by executing theSTOPstatement), and does not handle the condition itself, also sets theSTOPattribute of its corresponding asynchronous request handle toTRUE.If any errors occur when the event procedure attempts to execute, OpenEdge displays an error message in the context of the blocking I/O statement, and no information is stored in the asynchronous request handle. Errors where this might occur include, for example, an event procedure whose
INPUTparameters do not match in order and type with the output parameters from the remote request.Obtaining parameter values
As explained earlier, the values returned for
OUTPUTorINPUT-OUTPUTparameters on an asynchronous remote procedure are not returned to theRUNstatement as for a synchronous remote procedure. Instead, they are returned in the correspondingINPUTparameters of the specified event procedure.Note that
INPUTparameters in an event procedure observe the same rules of definition and scoping as any internal procedure, as shown:
Thus, in this example, the
order-tabletemp-table (defined in the outer block) receives its content directly from theorder-tableINPUTparameter of theGetOrderRecordsevent procedure. However, you must explicitly assign the icount variable (defined in the outer block) to theorder-countparameter in order to make the parameter value available to the outer block. (That is, if you define theINPUTparameter as icount instead oforder-count, OpenEdge does not automatically make the parameter value available as icount in the outer block. Only theTABLEparameter is scoped to the outer block and thus receives its value from the parameter.)Note also that the event procedure checks for and handles any unhandled conditions generated from the execution of
order.pusing AppServer error-handling mechanisms.Obtaining the return value
You can obtain the return value for a remote procedure that you call asynchronously by invoking the
RETURN-VALUEfunction within the event procedure that handles the asynchronous request. This function thus returns the value specified by a correspondingRETURNstatement executed in the remote procedure. As for a synchronous request, if the remote procedure returns no value in theRETURNstatement, theRETURN-VALUEfunction returns the empty string ("").
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |